/**
 * 
 */
package de.cbf.cam.dsa.battle.logic.commands;

import java.util.ArrayList;
import java.util.List;

import de.cbf.cam.dsa.battle.exceptions.ParseCommandException;
import de.cbf.cam.dsa.model.entities.states.stateChanger.StateChangerBase;
import de.cbf.cam.dsa.model.entities.states.stateChanger.StateChangerPosition;

/**
 * @author Nebelritter
 *	example : pos:2.3;3.4;5.6
 */
public class OneCommandChangePosition extends OneCommandBase {
	/**
	 * @uml.property  name="seperator"
	 */
	private final String seperator =";";  
	
	public OneCommandChangePosition() {
		super();
		name="pos:";
	}

	@Override
	public List<StateChangerBase> evaluateCommand(String oneCommand)
			throws ParseCommandException {
		
		List<StateChangerBase> resultList = new ArrayList<StateChangerBase>();
		String stringValues=oneCommand.substring(name.length(),oneCommand.length());		
		try{
			//parse target coordinates
			int prevIndex = 0;
			int indexSemicolon = stringValues.indexOf(seperator);
			String stringValue = stringValues.substring(prevIndex, indexSemicolon);
			Float valueX = Float.parseFloat(stringValue);
			indexSemicolon++;
			
			prevIndex = indexSemicolon;
			indexSemicolon = stringValues.indexOf(seperator,indexSemicolon);
			stringValue = stringValues.substring(prevIndex, indexSemicolon);
			Float valueY = Float.parseFloat(stringValue);
			indexSemicolon++;
			
			prevIndex = indexSemicolon;			
			stringValue = stringValues.substring(prevIndex,stringValues.length());
			Float valueZ = Float.parseFloat(stringValue);
			
			StateChangerPosition changePosition = new StateChangerPosition(valueX,valueY,valueZ);
			resultList.add(changePosition);
		}catch (NumberFormatException e) {
			throw new ParseCommandException("Wrong parameters :",e);		
		}catch (StringIndexOutOfBoundsException e) {
			throw new ParseCommandException("Wrong parameters :",e);
		}	
		return resultList;
	}

}
